﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BLL.ComplexClasses;
using DAL;
using App_Log;
using App_Utils;
namespace BLL
{
    public class BL_Zone
    {
        public static List<Zone> GetAllZones()
        {
            List<Zone> objZone = new List<Zone>();
            
            try
            {
                clsLog.logMsg("Zone", "GetAllZones", "Started");

                DAL.ithubEntities db = new ithubEntities();
                var query = (from q in db.tblZones select q);

                query = query.OrderBy(m => m.location);

                List<tblZone> _objZone = query.ToList();
                foreach (tblZone item in _objZone)
                {
                    objZone.Add((Zone)App_Utils.clsUtils.ConvertToObject(item, new Zone()));
                }
            }
            catch (Exception ex)
            {
                clsLog.logError("Zone", "GetAllZones", ex.ToString());
            }
            return objZone;
        }

        public static Zone GetZonebyZoneId(int zone_id)
        {
            Zone objZone = new Zone();

            try
            {
                clsLog.logMsg("Zone", "GetZonebyZoneId", "Started");

                DAL.ithubEntities db = new ithubEntities();
                var query = (from q in db.tblZones where q.zone_id == zone_id select q).SingleOrDefault();

                if (query != null)
                {
                    objZone = (Zone)App_Utils.clsUtils.ConvertToObject(query, new Zone());
                }
                else
                {
                    objZone = null;
                }
            }
            catch (Exception ex)
            {
                clsLog.logError("Zone", "GetZonebyZoneId", ex.Message);
            }
            return objZone;
        }
    }
}
